const express = require("express");
const router = express.Router();
const { conMysql } = require("../db");

//根据taxNo 修改企业信息
router.post("/updateEnterprise", (req, res) => {
    let { enterprise_id, enterprise_name, enterprise_desc, tax_no, contact_person, contact_number, enterprise_introduction = '' } = req.body;
    console.log(req.body);
    //判断是否为空
    if (!enterprise_id || !enterprise_name || !enterprise_desc || !tax_no || !contact_person || !contact_number) {
        res.output("修改信息不能为空", 1001, null);
        return;
    }
    //根据uid查询业务员是否存在
    const sql1 = `select * from db_enterprise where enterprise_id='${enterprise_id}'`;

    conMysql(sql1).then((result) => {
        if (result.length == 0) {
            res.output("企业不存在", 1001, null);
            return;
        }
        //修改企业信息
        const sql = `update db_enterprise set enterprise_name='${enterprise_name}',enterprise_desc= '${enterprise_desc}',tax_no='${tax_no}',contact_person='${contact_person}',contact_number='${contact_number}',enterprise_introduction='${JSON.stringify(enterprise_introduction)}' where enterprise_id='${enterprise_id}'`;
        conMysql(sql)
            .then((result) => {
                res.output("修改成功", 0, null);
            })
            .catch((err) => {
                res.output(err, 500, null);
            });
    }).catch((err) => {
        res.output(err, 500, null);
    })



})
module.exports = router;